package com.zc.iotDevice.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.zc.iotDevice.domain.IotDeviceSubsidiary;
import com.zc.iotDevice.domain.IotDeviceSubsidiaryPort;
import com.zc.iotDevice.service.IIotDeviceSubsidiaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 设备附属Controller
 *
 * @author gaojikun
 * @date 2023-05-16
 */
@RestController
@RequestMapping("/smart/subsidiary")
public class IotDeviceSubsidiaryController extends BaseController {
    @Autowired
    private IIotDeviceSubsidiaryService iotDeviceSubsidiaryService;

    /**
     * 查询设备附属列表
     */
    @PreAuthorize("@ss.hasPermi('smart:subsidiary:list')")
    @GetMapping("/list")
    public TableDataInfo list(IotDeviceSubsidiary iotDeviceSubsidiary) {
        startPage();
        List<IotDeviceSubsidiary> list = iotDeviceSubsidiaryService.selectIotDeviceSubsidiaryList(iotDeviceSubsidiary);
        return getDataTable(list);
    }

    /**
     * 导出设备附属列表
     */
    @PreAuthorize("@ss.hasPermi('smart:subsidiary:export')")
    @Log(title = "设备附属", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IotDeviceSubsidiary iotDeviceSubsidiary) {
        List<IotDeviceSubsidiary> list = iotDeviceSubsidiaryService.selectIotDeviceSubsidiaryList(iotDeviceSubsidiary);
        ExcelUtil<IotDeviceSubsidiary> util = new ExcelUtil<>(IotDeviceSubsidiary.class);
        util.exportExcel(response, list, "设备附属数据");
    }

    /**
     * 获取设备附属详细信息
     */
    @PreAuthorize("@ss.hasPermi('smart:subsidiary:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(iotDeviceSubsidiaryService.selectIotDeviceSubsidiaryById(id));
    }

    /**
     * 获取设备附属端口详细信息
     */
    @PreAuthorize("@ss.hasPermi('smart:subsidiary:query')")
    @GetMapping(value = "/getSubsidiaryPort/{id}")
    public AjaxResult getSubsidiaryPort(@PathVariable("id") Long id) {
        return iotDeviceSubsidiaryService.getSubsidiaryPort(id);
    }

    /**
     * 获取设备附属端口信息
     */
    @PreAuthorize("@ss.hasPermi('smart:subsidiary:query')")
    @GetMapping(value = "/getSubsidiaryList/{id}")
    public AjaxResult getSubsidiaryList(@PathVariable("id") Long id) {
        return AjaxResult.success(iotDeviceSubsidiaryService.selectIotDeviceSubsidiaryPortListById(id));
    }

    /**
     * 新增设备附属
     */
    @PreAuthorize("@ss.hasPermi('smart:subsidiary:add')")
    @Log(title = "设备附属", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IotDeviceSubsidiary iotDeviceSubsidiary) {
        return toAjax(iotDeviceSubsidiaryService.insertIotDeviceSubsidiary(iotDeviceSubsidiary));
    }

    /**
     * 新增设备附属端口
     */
    @PreAuthorize("@ss.hasPermi('smart:subsidiary:add')")
    @Log(title = "设备附属", businessType = BusinessType.INSERT)
    @PostMapping(value = "/addSubsidiaryPort")
    public AjaxResult addSubsidiaryPort(@RequestBody IotDeviceSubsidiaryPort iotDeviceSubsidiaryPort) {
        return iotDeviceSubsidiaryService.addSubsidiaryPort(iotDeviceSubsidiaryPort);
    }

    /**
     * 修改设备附属
     */
    @PreAuthorize("@ss.hasPermi('smart:subsidiary:edit')")
    @Log(title = "设备附属", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IotDeviceSubsidiary iotDeviceSubsidiary) {
        return toAjax(iotDeviceSubsidiaryService.updateIotDeviceSubsidiary(iotDeviceSubsidiary));
    }

    /**
     * 修改设备附属端口
     */
    @PreAuthorize("@ss.hasPermi('smart:subsidiary:edit')")
    @Log(title = "设备附属", businessType = BusinessType.UPDATE)
    @PutMapping(value = "/updateSubsidiaryPort")
    public AjaxResult updateSubsidiaryPort(@RequestBody IotDeviceSubsidiaryPort iotDeviceSubsidiaryPort) {
        return iotDeviceSubsidiaryService.updateSubsidiaryPort(iotDeviceSubsidiaryPort);
    }

    /**
     * 删除设备附属
     */
    @PreAuthorize("@ss.hasPermi('smart:subsidiary:remove')")
    @Log(title = "设备附属", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iotDeviceSubsidiaryService.deleteIotDeviceSubsidiaryByIds(ids));
    }

    /**
     * 删除设备附属端口
     */
    @PreAuthorize("@ss.hasPermi('smart:subsidiary:remove')")
    @Log(title = "设备附属", businessType = BusinessType.DELETE)
    @DeleteMapping("/delSubsidiaryPort/{id}")
    public AjaxResult delSubsidiaryPort(@PathVariable Long id) {
        return iotDeviceSubsidiaryService.delSubsidiaryPort(id);
    }

    /**
     * 查询设备列表
     */
    @PreAuthorize("@ss.hasPermi('smart:subsidiary:query')")
    @GetMapping("/getIotDeviceList")
    public AjaxResult getIotDeviceList() {
        return iotDeviceSubsidiaryService.getIotDeviceList();
    }

    /**
     * 查询运营商列表
     */
    @PreAuthorize("@ss.hasPermi('smart:subsidiary:query')")
    @GetMapping("/getOperatorList")
    public AjaxResult getOperatorList() {
        return iotDeviceSubsidiaryService.getOperatorList();
    }

    /**
     * 设备类型
     *
     * @return AjaxResult
     */
    @PreAuthorize("@ss.hasPermi('smart:subsidiary:query')")
    @GetMapping("/getDeviceTypeList")
    public AjaxResult getDeviceTypeList() {
        return iotDeviceSubsidiaryService.getDeviceTypeList();
    }

    /**
     * 直流交流类型
     *
     * @return AjaxResult
     */
    @PreAuthorize("@ss.hasPermi('smart:subsidiary:query')")
    @GetMapping("/getCurrentTypeList")
    public AjaxResult getCurrentTypeList() {
        return iotDeviceSubsidiaryService.getCurrentTypeList();
    }
}
